package com.itheima.bootdemo1.controller;

import com.itheima.bootdemo1.pojo.Books;
import com.itheima.bootdemo1.pojo.Enterprise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/books")
public class BookController {

    @Value("${enterprise.name}")
    private String name;
    @Value("${enterprise.age}")
    private Integer age;
    @Value("${enterprise.tel}")
    private String tel;
    @Value("${enterprise.subject[1]}")
    private String sub1;

    /*第二种  我们不用  框架底层用*/
    @Autowired
    private Environment environment;

    /*第三种 pojo封装 用的比较多*/
    @Autowired
    private Enterprise enterprise;
    @Autowired
    private Books books;

    @GetMapping("{id}")
    public String hello(@PathVariable Integer id){
        System.out.println("----------1---------");
        System.out.println(name);
        System.out.println(age);
        System.out.println(tel);
        System.out.println(sub1);
        System.out.println("----------2---------");
        System.out.println(environment.getProperty("enterprise.name"));
        System.out.println("----------3--------");
        System.out.println(enterprise);
        System.out.println(books);
        System.out.println("----------2---------");
        System.out.println("id="+id);
        return "你好啊";
    }

}
